package com.webserver.controller;

import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;
import qrcode.QRCodeUtil;
import sun.text.normalizer.NormalizerBase;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 工具相关
 */
public class ToolsController {
//    public static void main(String[] args) {
//        String str="你在干什么";
//        try {
//            FileOutputStream fos=new FileOutputStream("ma.jpg");
//            QRCodeUtil.encode(str,"./mv.jpg",fos,true);
//            System.out.println("生成完毕！");
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
    /**
     * 生成二维码
     * @param request
     * @param response
     */
    public void createQR(HttpRequest request, HttpResponse response) {
        String content=request.getParameter("content");
        try {
            QRCodeUtil.encode(content,response.getOutputStream());
            response.setContentType("image/jpeg");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
